package com.zone.domain.rebate.service.settle.impl;

import com.zone.domain.common.factory.FactoryName;
import com.zone.domain.credit.model.entity.UserCreditAdjustAmountEntity;
import com.zone.domain.credit.model.valobj.TradeNameEnum;
import com.zone.domain.credit.model.valobj.TradeTypeEnum;
import com.zone.domain.credit.service.IUserCreditAccountQuoteService;
import com.zone.domain.rebate.model.valobj.BehaviorTypeEnum;
import com.zone.domain.rebate.model.valobj.RebateTypeEnum;
import com.zone.domain.rebate.service.settle.IUserBehaviorRebateSettle;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author: zongzi
 * @description: 签到返利-积分
 * @date: 2025/3/11
 */
@Slf4j
@Component
public class SignIntegralRebateSettle implements IUserBehaviorRebateSettle, FactoryName {
    @Autowired
    private IUserCreditAccountQuoteService userCreditAccountQuoteService;

    @Override
    public void execute(String userId, String behaviorType, String rebateType, String rebateConfig) {
        // 交易金额
        BigDecimal amount = new BigDecimal(rebateConfig);

        UserCreditAdjustAmountEntity userCreditAdjustAmountEntity = new UserCreditAdjustAmountEntity();
        userCreditAdjustAmountEntity.setUserId(userId);
        userCreditAdjustAmountEntity.setTradeName(TradeNameEnum.BEHAVIOR_REBATE.getCode());
        userCreditAdjustAmountEntity.setTradeTypeEnum(TradeTypeEnum.FORWARD);
        userCreditAdjustAmountEntity.setAmount(amount);
        userCreditAdjustAmountEntity.setOutBusinessNo(RandomStringUtils.randomNumeric(12));
        userCreditAccountQuoteService.adjustAmount(userCreditAdjustAmountEntity);
    }

    @Override
    public String getName() {
        return String.format("%s_%s", BehaviorTypeEnum.SIGN.getCode(), RebateTypeEnum.INTEGRAL.getCode());
    }
}
